$webwork.htmlEncode($page.space.name) : Paletted images tutorial
This page last changed on Aug 07, 2007 by aaime.
Geoserver 1.5.2 onwards has the ability to output good quality 256 color images. This tutorial introduces you to the palette concepts, the various image generation options, and offers a quality/resource comparison of them in different situations. What are paletted imagesSome image formtas, such as GIF or PNG, can use a palette, that is, a table of (usually) 256 colors to allow for better compression. Basically, instead of representing each pixel with its full color triplet, that is 24bits (plus eventual 8 more for transparency), they use a 8 bit index that represent the position inside the palette, and thus the color. In the latter case, paletted images smaller footprint is usually a big gain in both performance and costs, because more data can be served with the same internet connection, and the clients will obtain responses faster. Formats and antialiasingInternet standards offer a variety of image formats, all having different strong and weak point. The three most common formats are:
So, as it turns out, paletted images can be used with profit on vector data sets, either using the PNG8 or GIF formats. The following zoom of an image shows antialiasing in action: Options to enable paletted outputThe easiest way to get a paletted image output is to ask for a 256 color output format, such as:
These output formats, if no other parameters are provided, do compute the optimal palette on the fly. As you'll see, this is an expensive process (CPU bound), but as you'll see, depending on the speed of the network connecting the server and the client, the extra cost can be ignored (especially if the bottleneck can be found in the network instead of the server CPU). Optimal palette computation is anyways a repetitive work that can be done up front: a user can compute the optimal palette once, and tell GeoServer to use it.
An example with vector dataEnough theory, let's have a look at how to deal with paletted images in practice. We'll use the tiger-ny basemap to gather some numbers, and in particular the following map request: http://localhost:8080/geoserver/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&LAYERS=tiger-ny&BBOX=-74.022019,40.701196,-73.992366,40.720964&HEIGHT=400&WIDTH=600&FORMAT=image/png
and we'll change various parameters in order to play with formats and palettes. Here goes the sampler:
The attachments include also the GIF outputs, whose size, appearance and generation time does not differ significantly from the PNG outputs. As we can see, depending on the choice we have a variation on the image quality, size and generation time (which has been recorded using the FasterFox Firefox extension timer, with the browser sitting on the same box as the server). Using palette=xxx provides the best match in speed and size, thought using the built in internet safe palette altered the colors. Then again, the real gain can be seen only by assuming a certain connection speed between the server and the client, and adding the time required to move the image to the client. The following table provides some results:
Legend:
As the table shows, the full color PNG image takes usually a lot more time than other formats, unless it's being served over a fast network (and even in this case, one should consider network congestion as well). The png8 output format proves to be a good choice if the connection is slow, whilst the extra work done in looking up an optimal palette always pays back in faster map delivery. Generating the custom paletteThe nyp.pal file has been generated using IrfanView, on Windows. The steps are simple:
An example with raster dataTo give you an example when paletted images may not fit the bill, let's consider the sf:dem coverage from the sample data, and repeat the same operation as before.
As the sampler shows, the JPEG output has the same quality as the full color image, is generated faster and uses only 1/5 of its size. At the opposite, the version using the internet safe palette is fast and small, but the output is totally ruined. Everything considered, JPEG is the clear winner, sporting good quality, fast image generation and a size that's half of the best png output we can get.
antialiasing.gif (image/gif)
antialiasing.gif (image/gif) tiger-ny-gif-safe-palette.gif (image/gif) tiger-ny-png-safe-palette.png (image/png) tiger-ny-gif.gif (image/gif) tiger-ny-png8.png (image/png) tiger-ny-png24.png (image/png) tiger-ny-gif-custom-palette.gif (image/gif) tiger-ny-png-custom-palette.png (image/png) nyp.pal (application/octet-stream) dem-jpeg.jpeg (image/jpeg) dem-png-custom-palette.png (image/png) dem-png-safe-palette.png (image/png) dem-png8.png (image/png) dem-png24.png (image/png) |
Document generated by Confluence on Jan 16, 2008 23:27 |